﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Generator.SetBaseTypeCodeGenerator
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.CodeDom;
using System.Web.Razor.Parser.SyntaxTree;

namespace System.Web.Razor.Generator
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Represents a code generator for set base type.</summary>
  public class SetBaseTypeCodeGenerator : SpanCodeGenerator
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Initializes a new instance of the <see cref="T:System.Web.Razor.Generator.SetBaseTypeCodeGenerator" /> class.</summary>
    /// <param name="baseType">The set base type.</param>
    public SetBaseTypeCodeGenerator(string baseType) => this.BaseType = baseType;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets or sets the set base type.</summary>
    /// <returns>The set base type.</returns>
    public string BaseType { get; private set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Generates the code for this set base type.</summary>
    /// <param name="target">The source span that contains the set base type to generate code.</param>
    /// <param name="context">The context of the code generator.</param>
    public override void GenerateCode(Span target, CodeGeneratorContext context)
    {
      context.GeneratedClass.BaseTypes.Clear();
      context.GeneratedClass.BaseTypes.Add(new CodeTypeReference(this.ResolveType(context, this.BaseType.Trim())));
      if (!context.Host.DesignTimeMode)
        return;
      int generatedCodeStart = 0;
      string code = context.BuildCodeString((Action<CodeWriter>) (cw =>
      {
        generatedCodeStart = cw.WriteVariableDeclaration(target.Content, "__inheritsHelper", (string) null);
        cw.WriteEndStatement();
      }));
      int paddingCharCount;
      CodeSnippetStatement snippetStatement = new CodeSnippetStatement(CodeGeneratorPaddingHelper.Pad(context.Host, code, target, generatedCodeStart, out paddingCharCount));
      snippetStatement.LinePragma = context.GenerateLinePragma(target, generatedCodeStart + paddingCharCount);
      CodeSnippetStatement statement = snippetStatement;
      context.AddDesignTimeHelperStatement(statement);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Resolves the given set base type.</summary>
    /// <returns>The resolved set base type.</returns>
    /// <param name="context">The context of the code generator.</param>
    /// <param name="baseType">The set base type to resolve.</param>
    protected virtual string ResolveType(CodeGeneratorContext context, string baseType) => baseType;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Returns the string representation for this instance.</summary>
    /// <returns>The string representation for this instance.</returns>
    public override string ToString() => "Base:" + this.BaseType;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified object is equal to this instance.</summary>
    /// <returns>true if the specified object is equal to this instance; otherwise, false.</returns>
    /// <param name="obj">The object to compare to this instance.</param>
    public override bool Equals(object obj) => obj is SetBaseTypeCodeGenerator typeCodeGenerator && string.Equals(this.BaseType, typeCodeGenerator.BaseType, StringComparison.Ordinal);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets the hash code for this current instance.</summary>
    /// <returns>The hash code for this current instance.</returns>
    public override int GetHashCode() => this.BaseType.GetHashCode();
  }
}
